//
//  TabBarController.swift
//  SwiftQiushi
//
//  Created by ch on 2020/10/16.
//  Copyright © 2020 ch. All rights reserved.
//

import UIKit

class TabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //替换为自定义的TabBar
        setValue(TabBar(), forKey: "tabBar")
        //背景不透明
        tabBar.barTintColor = UIColor.white
    

        //home
        addChild("糗事", "common_btn_under_fw_n", "common_btn_under_fw_s", HomeViewController.self)
        
        //trend
        addChild("动态", "common_btn_under_home_n", "common_btn_under_home_s", TrendViewController.self)
        
        //live
        addChild("直播", "common_btn_under_hz_n", "common_btn_under_hz_s", LiveViewController.self)
        
        //mine
        addChild("我的", "common_btn_under_wd_n", "common_btn_under_wd_s", MineViewController.self)
    }
    
    //添加控制器的方法
    func addChild(_ title: String,
                  _ image: String,
                  _ selectedImage: String,
                  _ type: UIViewController.Type) {
        
        let child = UINavigationController(rootViewController: type.init())
        child.title = title
        child.tabBarItem.image = UIImage(named: image)
        child.tabBarItem.selectedImage = UIImage(named: selectedImage)
        child.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.black], for: .selected)
        addChild(child)
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

